﻿using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;

namespace YArchitech.Revit
{
	public class RectDuctAndTerminalsFilter : ISelectionFilter
	{
		public bool AllowElement(Element elem)
		{
			if (elem is Duct)
			{
				Duct duct = elem as Duct;
				YJKPiping<Duct> hypiping = new YJKPiping<Duct>(duct);
				LocationCurve locationCurve = duct.Location as LocationCurve;
				if (Math.Abs(locationCurve.Curve.GetEndPoint(0).Z - locationCurve.Curve.GetEndPoint(1).Z) < 0.0065616797900262466 && YJKRevitTools.GetConnectorSharpName(hypiping.StartConnector.Connector) == "矩形")
				{
					return true;
				}
			}
			else if (elem is FamilyInstance && elem.Category.Id.IntegerValue == -2008013)
			{
				FamilyInstance elem2 = elem as FamilyInstance;
				if (YJKRevitTools.GetConnectorSharpName(YJKRevitTools.GetElementConnector(1, elem2)) == "矩形")
				{
					return true;
				}
			}
			return false;
		}

		public bool AllowReference(Reference reference, XYZ position)
		{
			return false;
		}
	}
}
